﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using LEEAAttendanceControl.Web.Services;
using System.ServiceModel.DomainServices.Client;
using LEEAAttendanceControl.General;
using LEEAAttendanceControl.Web;

namespace LEEAAttendanceControl.Views
{
    public partial class Companies : Page
    {

        LEEAContext dc = new LEEAContext();

        public Companies()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        /// <summary> 
        /// Loads the data for the application. 
        /// </summary> 

        private void OnChangesSubmitted(SubmitOperation so)
        {
            if (so.HasError)
            {
                so.MarkErrorAsHandled();
                MessageBox.Show(ApplicationStrings.GeneralError);
            }
            else
            {
                MessageBox.Show(ApplicationStrings.GeneralSave, ApplicationStrings.GeneralSave, MessageBoxButton.OK);
            }
        }



        private void ImgNewCompany_Click(object sender, RoutedEventArgs e)
        {
            CompanyEdit compedit = new CompanyEdit();
            compedit.LoadData(No.Zero);
            compedit.Closed += new EventHandler(CompanyEdit_Closed);
            compedit.Show();
        }

        private void LnkEditCompany_Click(object sender, RoutedEventArgs e)
        {
            Company currcompany = GRDCompany.SelectedItem as Company;
            CompanyEdit compedit = new CompanyEdit();
            compedit.LoadData(currcompany != null ? currcompany.ID : No.Zero);
            compedit.Closed += new EventHandler(CompanyEdit_Closed);
            compedit.Show();
        }

        void CompanyEdit_Closed(object sender, EventArgs e)
        {
            CompanyDataSource.Load();
        }

        private void CompanyDataSource_LoadingData(object sender, LoadingDataEventArgs e)
        {
            e.LoadBehavior = LoadBehavior.RefreshCurrent;
        }

        private void LnkDeleteCompany_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show(ApplicationStrings.DeleteMessage, ApplicationStrings.Delete, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                CompanyDataSource.DataView.Remove(GRDCompany.SelectedItem);
                CompanyDataSource.SubmitChanges();
            }
        }
    }
}
